package com.tour.controller;


import com.tour.config.ResponseWrapper;
import com.tour.entity.Shop;
import com.tour.service.impl.ShopServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lel
 * @since 2021-03-30
 */
@RestController
@Api(tags = "土特产管理")
public class ShopController {

    @Autowired
    ShopServiceImpl shopService;

    @ApiOperation("增加店铺")
    @PostMapping("/addShop")
    public ResponseWrapper addShop(@RequestBody Shop shop){
        ResponseWrapper wrapper = shopService.addShop(shop);
        return wrapper;
    }
    @ApiOperation("修改店铺")
    @PutMapping("/updateShop")
    public ResponseWrapper updateShop(@RequestBody Shop shop){
        ResponseWrapper wrapper = shopService.updateShop(shop);
        return wrapper;
    }

    @ApiOperation("查询所有店铺或者模糊查询")
    @GetMapping("/app/findShop")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize",value = "每页展示的数据条数",defaultValue = "10"),
            @ApiImplicitParam(name = "pageNum",value = "页码数",defaultValue = "1"),
            @ApiImplicitParam(name = "name",value = "店铺名")
    })
    public ResponseWrapper findShop(@RequestParam(name = "pageSize",defaultValue = "10")Integer pageSize,
                                    @RequestParam(name = "pageNum",defaultValue = "1")Integer pageNum,
                                    @RequestParam(name = "name",required = false)String name){
        ResponseWrapper wrapper = shopService.findShop(name,pageSize,pageNum);
        return wrapper;
    }

    @ApiOperation("查询某个店铺")
    @GetMapping("/app/getShoBysId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize",value = "评论每页展示的数据条数",defaultValue = "10"),
            @ApiImplicitParam(name = "pageNum",value = "评论页码数",defaultValue = "1"),
            @ApiImplicitParam(name = "sId",value = "店铺id"),
            @ApiImplicitParam(name = "compageSize",value = "商品每页展示的数据条数",defaultValue = "10"),
            @ApiImplicitParam(name = "compageNum",value = "商品页码数",defaultValue = "1"),
    })
    public ResponseWrapper getShoBysId(@RequestParam(name = "pageSize",defaultValue = "10")Integer pageSize,
                                       @RequestParam(name = "pageNum",defaultValue = "1")Integer pageNum,
                                       @RequestParam(name = "sId")Integer sId,
                                       @RequestParam(name = "compageSize",defaultValue = "10")Integer compageSize,
                                       @RequestParam(name = "compageNum",defaultValue = "1")Integer compageNum){
        ResponseWrapper wrapper = shopService.getShoBysId(sId,pageSize,pageNum,compageSize,compageNum);
        return wrapper;
    }

    @ApiOperation("删除某个店铺")
    @DeleteMapping("/deleteShop")
    @ApiImplicitParam(name = "sId",value = "商店id")
    public ResponseWrapper deleteShop(@RequestParam(name = "sId")Integer sId){
        ResponseWrapper wrapper = shopService.deleteShop(sId);
        return wrapper;
    }

    /**
     上传文件的方法，将文件上传到某个存在的位置
     @param file 文件名
     */
    @ApiOperation("上传视频")
    @PostMapping("/upload")
    public ResponseWrapper upload(@RequestParam("file") MultipartFile file)throws Exception{
        // 这里由于逻辑较多所以封装了一个util
        ResponseWrapper wrapper = shopService.upload(file);
        return wrapper;
    }
}

